class ServiceController < ApplicationController
 
  require 'net/http'
  require 'rexml/document'
	
  def index
  	@participants = Participant.find(:all)
  end
  
  def who_play
  	@event = Event.find_by_cod(params[:id])
    @eventparticipant = Eventparticipant.find_all_by_event_idf(@event.id)
    respond_to do |format|
    format.xml { render :layout => false }
    end
  end

  def all_play
  	@event = Event.find(:all)
    respond_to do |format|
    format.xml { render :layout => false }
    end
  end
  
  # consume servicio web de un solo evento (sintaxis invalida)
  def who_play_consume 
      url = 'http://192.168.1.102:3000/service/who_play/3'    
      xml_data = Net::HTTP.get_response(URI.parse(url)).body  
      doc = REXML::Document.new(xml_data)
      @nombre= doc.elements['evento'].elements["nombre"].text
  end
  
  # consume servicio web de todos los eventos
  def all_play_consume 
  	 @event=Event.find(params[:id])
  	 @dataevent=Eventparticipant.find_all_by_event_idf(@event.id)
  end
  
  # provee servicios de ganancias de usuario (falta completar la vista solo imprime login y nombre)
  def user_stats
  	 @user=User.find_by_login(params[:id])
  	 respond_to do |format|
     format.xml { render :layout => false }
  end
  end
  
  def create_bet

    @lol = params[:apuesta]

    
	@bet=Bet.find_by_id(1)
	respond_to do |format|
	format.xml
	end
  end

  
end
